package cmpe451.group7.ourcity.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Entity class for tags.
 */
@Entity
@Table(name = "tag")
public class Tag implements Serializable {

	private static final long serialVersionUID = 1L;

	private long tagID;
	private String mID; // freebase id
	private String tagName;
	private String notableName;

	// @ManyToMany(mappedBy = "tags")
	// private Set<Place> places = new HashSet<Place>();

	public Tag() {
		this(null, null, null);
	}

	public Tag(String mID, String tagName, String notableName) {
		this.mID = mID;
		this.tagName = tagName;
		this.notableName = notableName;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "tagID")
	public long getTagID() {
		return tagID;
	}

	public void setTagID(long tagID) {
		this.tagID = tagID;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (tagID ^ (tagID >>> 32));
		result = prime * result + ((tagName == null) ? 0 : tagName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tag other = (Tag) obj;
		if (tagID != other.tagID)
			return false;
		if (tagName == null) {
			if (other.tagName != null)
				return false;
		} else if (!tagName.equals(other.tagName))
			return false;
		return true;
	}

	@Column(unique = true, nullable = true)
	public String getmID() {
		return mID;
	}

	public void setmID(String mID) {
		this.mID = mID;
	}

	@Override
	public String toString() {
		return tagName + (notableName == null ? "" : " (" + notableName + ")");
	}

	public String getNotableName() {
		return notableName;
	}

	public void setNotableName(String notableName) {
		this.notableName = notableName;
	}

}
